{% extends "layout/control.html" %}

{% block title %}个人中心{% endblock %}

{% block head %}
<style>
    #page {
        text-align: center;
    }
    .waterfall {
        -moz-column-count: auto;
        -webkit-column-count: auto;
        column-count: auto;
        -moz-column-width: 15em;
        -webkit-column-width: 15em;
        column-width: 15em;
        -moz-column-gap: 1em;
        -webkit-column-gap: 1em;
        column-gap: 1em;
    }
    .pin {
        margin: 0 0.125em 1em;
        /*
        padding: 1em;
        -moz-page-break-inside: avoid;
        -webkit-column-break-inside: avoid;
        break-inside: avoid;
        background: white;
        -moz-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.24);
        -webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.24);
        box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px 0 rgba(0, 0, 0, 0.24);
        */
    }
    .pin img {
        width: 100%;
        /*padding-bottom: 1em;*/
        margin-bottom: 0.5em;
        border-bottom: 0px solid #fff;
    }
    {% if g.userinfo.ucfg_mypic_scale %}
    .pin img:hover {
        transform:scale({{ g.userinfo.ucfg_mypic_scale|float }});
    }
    {% endif %}
    .pin .description {
        text-align: center;
        position: absolute;
    }
    body .my-layer .layui-layer-btn .layui-layer-btn0 {
        background: #FF5722;
        border-color: #FF5722;
        color: #fff;
    }
    body .my-layer .layui-layer-btn .layui-layer-btn2 {
        background: #01AAED;
        border-color: #01AAED;
        color: #fff;
    }
    body .linktoken-layer .layui-layer-btn .layui-layer-btn0 {
        background: #01AAED;
        border-color: #01AAED;
        color: #fff;
    }
    body .layui-laypage .layui-laypage-count {
        background-color: #F6F6F6
    }
    #albums {
        margin-bottom: 10px;
    }
</style>
<!--头像裁剪-->
<link rel="stylesheet" href="/static/css/cropper.min.css">
<link rel="stylesheet" href="/static/css/ImgCropping.css">
{% endblock %}

{% block content %}
<div class="layui-container">
    <div class="layui-tab layui-tab-brief" lay-filter="tab">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="profile">个人资料</li>
            <li lay-id="password">修改密码</li>
            <li lay-id="setting">用户设置<span class="layui-badge-dot"></span>
            </li>
            <li lay-id="picbed">我的图片</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form lay-filter="profileForm" class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" required="" autocomplete="off" value="{{ g.userinfo.username }}"
                                class="layui-input layui-disabled" disabled="">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            {% if g.is_admin %}
                            <scan style="color: #5FB878;font-weight: bold;">你好，管理员！</scan>
                            {% endif %}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nickname" autocomplete="off" value="{{ g.userinfo.nickname }}"
                                placeholder="个性化的别名" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <div class="layui-input-inline">
                            <input type="text" name="avatar" autocomplete="off" value="{{ g.userinfo.avatar }}"
                                placeholder="头像URL或裁剪上传" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <a href="javascript:;" style="color: #393D49" id="uploadAvatar"><i class="layui-icon layui-icon-upload-drag"></i>上传头像</a>
                        </div>
                    </div>
                    {{ intpl("profile") }}
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-filter="profile" lay-submit="">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="passwd" required="" lay-verify="required" autocomplete="off"
                                class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">至少6个字符</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="repasswd" required="" lay-verify="required" autocomplete="off"
                                class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-filter="passwd" lay-submit="">确认修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                {{ intpl("before_usersetting") }}
                <blockquote class="layui-elem-quote">以下是您在站点中的个性化设置，仅在个人登录后有效，不会影响到其他人！</blockquote>
                <form class="layui-form" id="control" lay-filter="setting" autocomplete="off">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">背景图</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="ucfg_bg_mg" value="{{ g.userinfo.ucfg_bg_mg }}"
                                    placeholder="PC端背景图地址" autocomplete="off" class="layui-input" list="bg_mg_defaults">
                                <datalist id="bg_mg_defaults">
                                    <option value="https://open.saintic.com/api/bingPic">
                                    <option value="{{ url_for('static', filename='img/bg1.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/bg2.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/bg3.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/bg4.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/bg5.jpg') }}">
                                </datalist>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">移动端背景</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="ucfg_bg_mobile" value="{{ g.userinfo.ucfg_bg_mobile }}"
                                    placeholder="移动端背景图地址" autocomplete="off" class="layui-input"
                                    list="bg_mobile_defaults">
                                <datalist id="bg_mobile_defaults">
                                    <option value="{{ url_for('static', filename='img/mbg1.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/mbg2.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/mbg3.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/mbg4.jpg') }}">
                                    <option value="{{ url_for('static', filename='img/mbg5.jpg') }}">
                                </datalist>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">背景透明度</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="number" step=0.1 min=0 max=1 name="ucfg_bg_ransparency"
                                    value="{{ g.userinfo.ucfg_bg_ransparency }}" placeholder="背景图透明度" autocomplete="off"
                                    class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">默认相册</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" class="layui-input" name="ucfg_default_album" id="render_default_album" placeholder="默认加载的相册" value="{{ g.userinfo.ucfg_default_album }}" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">图片放大度</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="number" step=0.1 min=1 max=2 name="ucfg_mypic_scale"
                                value="{{ g.userinfo.ucfg_mypic_scale }}" placeholder="图片悬浮放大倍数"
                                autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">图片加载数</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="number" step=1 min=1 max=100 name="ucfg_mypic_limit"
                                value="{{ g.userinfo.ucfg_mypic_limit }}" placeholder="加载图片的数量"
                                autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-about" id="urlprocesstip"></i> URL后缀</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" name="ucfg_url_rule" placeholder="图片处理规则" autocomplete="off" class="layui-input" value="{{ g.userinfo.ucfg_url_rule }}">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-about" id="urlsensetip"></i> 应用场景</label>
                            <div class="layui-input-inline" style="width: auto;">
                                <input type="checkbox" name="ucfg_urlrule_inloadmypic" title="图片加载时" lay-skin="primary" {% if is_true(g.userinfo.ucfg_urlrule_inloadmypic) %}checked{% endif %} value="1">
                                <input type="checkbox" name="ucfg_urlrule_incopyurl" title="URL" lay-skin="primary" {% if is_true(g.userinfo.ucfg_urlrule_incopyurl) %}checked{% endif %} value="1">
                                <input type="checkbox" name="ucfg_urlrule_incopyhtml" title="HTML" lay-skin="primary" {% if is_true(g.userinfo.ucfg_urlrule_incopyhtml) %}checked{% endif %} value="1">
                                <input type="checkbox" name="ucfg_urlrule_incopyrst" title="rST" lay-skin="primary" {% if is_true(g.userinfo.ucfg_urlrule_incopyrst) %}checked{% endif %} value="1">
                                <input type="checkbox" name="ucfg_urlrule_incopymd" title="Markdown" lay-skin="primary" {% if is_true(g.userinfo.ucfg_urlrule_incopymd) %}checked{% endif %} value="1">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">统计开关</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="ucfg_report_linktoken" title="LinkToken" {% if is_true(g.userinfo.ucfg_report_linktoken) %}checked{% endif %} value="1">
                        </div>
                    </div>
                    {% if is_true(g.site.upload_rule_overridden) %}
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片路径前缀规则</label>
                        <div class="layui-input-block">
                            <input type="radio" name="ucfg_upload_path_rule" value="default" title="默认(无目录)"
                                {% if g.userinfo.ucfg_upload_path_rule|d("default") == "default" %}checked="checked" {% endif %}
                                autocomplete="off">
                            <input type="radio" name="ucfg_upload_path_rule" value="date1" title="年/月/日"
                                {% if g.userinfo.ucfg_upload_path_rule == "date1" %}checked="checked" {% endif %} autocomplete="off">
                            <input type="radio" name="ucfg_upload_path_rule" value="date2" title="年月日"
                                {% if g.userinfo.ucfg_upload_path_rule == "date2" %}checked="checked" {% endif %} autocomplete="off">
                            <input type="radio" name="ucfg_upload_path_rule" value="" title="跟随全局设置"
                                {% if not g.userinfo.ucfg_upload_path_rule %}checked="checked" {% endif %} autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片文件命名规则</label>
                        <div class="layui-input-block">
                            <input type="radio" name="ucfg_upload_file_rule" value="default" title="默认(原名)"
                                {% if g.userinfo.ucfg_upload_file_rule|d("default") == "default" %}checked="checked" {% endif %}
                                autocomplete="off">
                            <input type="radio" name="ucfg_upload_file_rule" value="time1" title="时间戳(毫秒)"
                                {% if g.userinfo.ucfg_upload_file_rule == "time1" %}checked="checked" {% endif %} autocomplete="off">
                            <input type="radio" name="ucfg_upload_file_rule" value="time2" title="时间戳+随机数"
                                {% if g.userinfo.ucfg_upload_file_rule == "time2" %}checked="checked" {% endif %} autocomplete="off">
                            <input type="radio" name="ucfg_upload_file_rule" value="time3" title="年月日时分秒+随机数"
                                {% if g.userinfo.ucfg_upload_file_rule == "time3" %}checked="checked" {% endif %} autocomplete="off">
                            <input type="radio" name="ucfg_upload_file_rule" value="" title="跟随全局设置"
                                {% if not g.userinfo.ucfg_upload_file_rule %}checked="checked" {% endif %} autocomplete="off">
                        </div>
                    </div>
                    {% endif %}
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: auto;"><i class="layui-icon layui-icon-about" id="userscripttip"></i> 开启用户脚本 <a href="{{ url_for('front.userscript', _external=True) }}" target="_blank" id="userscripturl"><i class="layui-icon layui-icon-link" style="font-size: 12px;"></i></a></label>
                            <div class="layui-input-inline" style="width: 50px;">
                                <input type="checkbox" name="ucfg_userscript" lay-skin="switch" lay-text="ON|OFF" lay-filter="userscript_btn"
                                {% if is_true(g.userinfo.ucfg_userscript) %}checked="checked" {% endif %} autocomplete="off"
                                value="1">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">LinkToken</label>
                            <div class="layui-input-inline" style="width: auto;">
                                <input type="text" name="ucfg_userscript_token"
                                value="{{ g.userinfo.ucfg_userscript_token }}" placeholder="用户脚本认证上传"
                                autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">快捷键</label>
                            <div class="layui-input-inline">
                                <input type="radio" name="ucfg_userscript_hotkey" value="ctrlKey" title="Ctrl"
                                    {% if g.userinfo.ucfg_userscript_hotkey == "ctrlKey" %}checked="checked" {% endif %} autocomplete="off">
                                <input type="radio" name="ucfg_userscript_hotkey" value="altKey" title="Alt"
                                    {% if g.userinfo.ucfg_userscript_hotkey == "altKey" %}checked="checked" {% endif %} autocomplete="off">
                            </div>
                        </div>
                    </div>
                    {{ intpl("usersetting") }}
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <div id="albums"></div>
                <div id="waterfall" class="waterfall"></div>
                <div id="page"></div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block script %}
{% include "ref/upload_show.html" %}
{% raw %}
<script type="text/html" id="linktoken_action">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs" lay-event="copy">复制</a>
        {{# if(d.status === "1" || d.status === 1) { }}
        <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="disable">禁用</a>
        {{# } else { }}
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="enable">启用</a>
        {{# } }}
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    </div>
</script>
<script type="text/html" id="toolbar">
    <div>
        <i class="layui-icon layui-icon-about" id="linktokentip"></i>
        <a href="javascript:;" lay-event="newLink" style="color:#009688;font-weight:bold">添加Token分权引用</a>
    </div>
</script>
<script type="text/html" id="show_editor_area">
    <form class="layui-form" style="padding:10px" lay-filter="linktokenForm">
        {{# if(d.action === "edit") { }}
        <div class="layui-form-item">
            <input type="text" class="layui-input layui-disabled" name="LinkId" autocomplete="off" required lay-verify="required" lay-verType="tips" value="{{ d.LinkToken }}" readonly>
        </div>
        {{# } }}
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="comment" placeholder="[可选]此引用的备注信息" autocomplete="off">
        </div>
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="album" placeholder="[可选]相册名，引用于上传图片接口时设置的默认相册" autocomplete="off">
        </div>
        <blockquote class="layui-elem-quote">分权引用限定条件，以下参数均可留空，逗号分隔多条</blockquote>
        <div class="layui-form-item">
            {{# if (!d.cors) { }}
                <input type="text" class="layui-input layui-disabled" name="allow_origin" placeholder="请联系管理员设置CORS Origin" autocomplete="off" readonly>
            {{# } else if (d.cors === "*") { }}
                <input type="text" class="layui-input" name="allow_origin" placeholder="origin: 允许调用的安全来源根域名，留空则不限制" autocomplete="off">
            {{# } else { }}
                <input type="text" class="layui-input" name="allow_origin" id="render_multi_origin" placeholder="origin: 允许调用的安全来源根域名，留空则不限制" autocomplete="off">
            {{# } }}
        </div>
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="allow_ip" placeholder="ip: 允许调用的安全来源IP，留空则不限制" autocomplete="off">
        </div>
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="allow_ep" id="render_multi_ep" placeholder="ep: 允许访问的路由端点，留空默认api.upload" autocomplete="off">
        </div>        
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="allow_method" id="render_multi_method" placeholder="method: 允许访问的HTTP方法，留空默认post" autocomplete="off">
        </div>
        <blockquote class="layui-elem-quote">允许访问规则，可使用运算符
            <scan style="color:#FF5722"> in, not in, </scan>
            <scan style="color:#009688">and, or, not, () </scan>
            定义访问条件，以此规则综合判断是否允许请求。<a href="https://docs.saintic.com/picbed/usage.html#linktoken" target="_blank" title="LinkToken文档"><i class="layui-icon layui-icon-link"></i></a>
        </blockquote>
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="interior_relation" placeholder="ir: 限定条件内部的规则, 格式: in/not in:opt" autocomplete="off">
        </div>
        <div class="layui-form-item">
            <input type="text" class="layui-input" name="exterior_relation" placeholder="er: 限定条件之间的规则, 格式: opt and/or/not opt and ()" autocomplete="off">
        </div>
        <div class="layui-form-item">
            {{# if(d.action === "create") { }}
            <button class="layui-btn layui-btn-sm layui-btn-fluid" lay-submit lay-filter="linktokenAdd">添加</button>
            {{# } }}
            {{# if(d.action === "edit") { }}
            <button class="layui-btn layui-btn-sm layui-btn-fluid" lay-submit lay-filter="linktokenModify">修改</button>
            {{# } }}
        </div>
    </form>
</script>
{% endraw %}
{% if request.args.album == "all" %}
{% set load_album = "" %}
{% else %}
{% set load_album = request.args.album or g.userinfo.ucfg_default_album %}
{% endif %}
<script>
    layui.use(['picbed', 'laypage', 'flow', 'form', 'element', 'layer', 'laytpl', 'util', 'table', 'tableSelect', 'avatar'], function () {
        var $ = layui.jquery,
            picbed = layui.picbed,
            util = layui.util,
            flow = layui.flow,
            form = layui.form,
            layer = layui.layer,
            table = layui.table,
            laytpl = layui.laytpl,
            element = layui.element,
            laypage = layui.laypage,
            avatar = layui.avatar,
            tableSelect = layui.tableSelect;

        //显示当前tab
        if (location.hash) {
            var layid = location.hash.replace(/^#!/, '').replace(/^#%21/, '').split('=')[0];
            element.tabChange('tab', layid);
        }
        //监听tab切换
        element.on('tab(tab)', function (data) {
            var othis = $(this),
                layid = othis.attr('lay-id');
            if (layid) {
                location.hash = '!' + layid;
            }
        });
        var curr = location.hash.replace('#!picbed=', ''),
            limit = parseInt("{{ request.args.limit or g.userinfo.ucfg_mypic_limit or 10 }}");
        var closeTip = function () {
            setTimeout(function() {
                layer.closeAll('tips');
            }, 1500);
        };
        //Token提示
        $("#tokentip").hover(function () {
            var tip = [
                "Token是目前唯一一种能在API请求中认证用户的方法，它具备API所有权，一旦泄露风险极大！",
                "所以建议您使用基于Token的分权引用LinkToken（用户设置）。",
                "更多请参考文档：<a href='https://docs.saintic.com/picbed/usage.html#token' target='_blank' style='color:#009688'>Token</a>",
            ].join("<br>");
            layer.tips(tip, this, {tips: 3, time: 0});
        }, closeTip);
        //URL后缀提示
        $("#urlprocesstip").hover(function () {
            let tip = [
                "URL后缀是在复制URL等应用场景时向链接追加的部分，实现图片裁剪、缩略等处理：",
                "依据对象存储参考以下文档：<a href='https://help.upyun.com/knowledge-base/image/' target='_blank' style='color:#009688'>又拍云图片处理</a>，<a href='https://developer.qiniu.com/dora/api/3683/img-directions-for-use' target='_blank' style='color:#009688'>七牛云图片处理</a>，<a href='https://help.aliyun.com/document_detail/99372.html' target='_blank' style='color:#009688'>阿里云OSS数据处理</a>，<a href='https://cloud.tencent.com/document/product/436/42214' target='_blank' style='color:#009688'>腾讯云COS数据处理</a>",
                "",
                "URL后缀设置格式如下：<scan style='color:red'>图片保存者(钩子名称):处理图片的分隔符与指令或样式</scan>，注意冒号，允许以逗号分隔多条！",
                "举例 => <scan style='color:#1E9FFF'>up2local:?v=1, up2upyun:!small</scan>，表示使用up2local保存的图片在场景中URL后缀增加<scan style='color:#1E9FFF'>?v=1</scan>，使用up2upyun保存的图片在场景中URL后缀增加<scan style='color:#1E9FFF'>!small</scan>",
                "",
                "更多请参考文档：<a href='https://docs.saintic.com/picbed/usage.html#url-process' target='_blank' style='color:#009688'>URL后缀</a>",
            ].join("<br>");
            layer.tips(tip, this, {tips: 3, time: 0});
        }, closeTip);
        $("#urlsensetip").hover(function () {
            var tip = [
                "即允许URL后缀使用的场景：",
                "我的图片页面加载图片时；",
                "图片详情复制URL时；",
                "图片详情复制HTML时；",
                "图片详情复制rST时；",
                "图片详情复制Markdown时。",
            ].join("<br>");
            layer.tips(tip, this, {tips: 3, time: 0});
        }, closeTip);
        //用户脚本提示
        $("#userscripttip").hover(function () {
            var tip = [
                "温馨提示：",
                '开启用户脚本并保存配置后，可以点击开关旁边<i class="layui-icon layui-icon-link"></i>图标进行安装或更新脚本。',
                '记得填写LinkToken，要求有<b>front.userscript, api.upload</b>端点的get和post权限！',
                "更多请参考文档：<a href='https://docs.saintic.com/picbed/usage.html#userscript' target='_blank' style='color:#009688'>UserScript</a>",
            ].join("<br>");
            layer.tips(tip, this, {tips:3, time: 0});
        }, closeTip);
        //渲染默认加载相册的select下拉多选
        function renderDefaultAlbumSelect() {
            let selectd_album = "{{ g.userinfo.ucfg_default_album or '' }}";
            if (selectd_album) {
                let sas = selectd_album.split(/\s*,\s*/);
                sas = sas.map(function(a) {
                    return picbed.getHash(a);
                });
                $("#render_default_album").attr("ts-selected", sas.join(","));
            }
            tableSelect.render({
                elem: '#render_default_album',	//定义输入框input对象 必填
                checkedKey: 'hash', //表格的唯一建值，非常重要，影响到选中状态 必填
                selectText: '确认选择',
                table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    url: "{{ url_for('api.album') }}", //不加载admin
                    parseData: function(res) {
                        return {
                            "code": res.code,
                            "msg": res.msg,
                            "count": res.data.length,
                            "data": res.data.map(function(a) {
                                return {
                                    hash: picbed.getHash(a),
                                    album: a,
                                    count: res.counter[a]
                                };
                            })
                        };
                    },
                    page: false,
                    size: 'sm',
                    width: 300,
                    height: 200,
                    cols: [[{
                        type: 'checkbox'
                    }, {
                        field: "hash",
                        title: "唯一标识",
                        hide: true
                    },{
                        field: "album",
                        title: "相册名",
                    }, {
                        field: "count",
                        title: "数量",
                        width: 60
                    }]]
                },
                done: function (elem, data) {
                    var NEWJSON = [];
                    layui.each(data.data, function (index, item) {
                        NEWJSON.push(item.album);
                    });
                    $("#render_default_album").val(NEWJSON.join(","));
                }
            });
        }
        //将所有图片数据提到"全局"
        var shaDatas = {};
        //获取我的图片流方法
        function get_pics(page, success) {
            var url_rules = JSON.parse('{{ g.userinfo.parsed_ucfg_url_rule|tojson }}'),
                url_rule_switch = JSON.parse('{{ g.userinfo.parsed_ucfg_url_rule_switch|tojson }}'),
                url = "{{ url_for('api.waterfall', sort='desc', is_mgr=request.args.is_mgr, album=load_album)|safe }}&limit=" + limit + "&page=" + page;
            picbed.ajax(url, function (res) {
                var html = res.data.map(function (img) {
                    img["ctime"] = util.toDateString(img.ctime * 1000);
                    img["is_control"] = true;
                    img["get_src"] = function(_type) {
                        //根据type返回src
                        var typeSwitch = url_rule_switch[_type];
                        if (typeSwitch === true) {
                            return img.src + (url_rules[img.sender] || "");
                        }
                        return img.src;
                    };
                    shaDatas[img.sha] = img;
                    return '<div class="pin"><img src="' + img.get_src("loadmypic") + '" data-sha="' + img.sha + '"></div>';
                }).join("");
                $("#waterfall").html(html);
                //flow.lazyimg();
                typeof success === "function" && success(res);
                $("#waterfall").find(".pin img").on("click", function() {
                    var sha = $(this).data("sha");
                    laytpl(upload_show_tpl.innerHTML).render(shaDatas[sha], function(html){
                        layer.open({
                            type: 1,
                            title: false,
                            closeBtn: true,
                            area: document.body.clientWidth > 550 ? '550px' : 'auto',
                            maxHeight: '500px',
                            id: 'upload_show_area',
                            skin: 'my-layer',
                            shade: 0.1,
                            shadeClose: true,
                            btn: ['删除', '关闭', '原图'],
                            btnAlign: 'c',
                            content: html,
                            success: function(layero, indexo) {
                                element.render('tab');
                                if (shaDatas[sha]["status"] === 'deleted') {
                                    layero.children(".layui-layer-btn").children(".layui-layer-btn0").text("已删除");
                                }
                                $(layero).find('.upload_show_copy').on('click', function() {
                                    var copyId = $(this).data('copyid');
                                    picbed.Clipboard.copy($(copyId).text());
                                });
                                //album set datalist
                                $("#list_user_albums").html(res.albums.map(function(a) {
                                    return '<option value="' + a + '">';
                                }).join(""));
                            },
                            yes: function(index, layero){
                                //按钮【删除】的回调
                                if (layero.children(".layui-layer-btn").children(".layui-layer-btn0").text() === "确认删除") {
                                    picbed.ajax("{{ url_for('api.shamgr', sha='') }}" + sha, function(res) {
                                        layer.msg("已删除", {icon:1});
                                        shaDatas[sha]["status"] = "deleted";
                                        layero.children(".layui-layer-btn").children(".layui-layer-btn0").text("已删除");
                                    }, {
                                        method: 'delete'
                                    });
                                } else {
                                    if (layero.children(".layui-layer-btn").children(".layui-layer-btn0").text() === "删除") {
                                        layero.children(".layui-layer-btn").children(".layui-layer-btn0").text("确认删除");
                                    }
                                }
                            },
                            btn2: function(index, layero){
                                //按钮【关闭】的回调
                                layer.close(index);
                            },
                            btn3: function(index, layero) {
                                //按钮【原图】的回调
                                var id = "jump-" + sha,
                                    a = document.createElement("a");
                                a.style.display='none';
                                a.setAttribute("href", shaDatas[sha].src);
                                a.setAttribute("target", "_blank");
                                a.setAttribute("id", id);
                                if(!document.getElementById(id)) {
                                    document.body.appendChild(a);
                                }
                                a.click();
                                return false;
                            },
                        });
                    });
                });
            }, {
                msgprefix: false,
                fail: function(res) {
                    $("#waterfall").text("无数据");
                }
            });
        }
        //初始加载图片
        get_pics(curr, function (res) {
            laypage.render({
                elem: 'page',
                count: res.count,
                limit: limit,
                hash: 'picbed',
                curr: curr, //起始页
                layout: ['count', 'prev', 'page', 'next'],
                jump: function (obj, first) {
                    if (!first) {
                        get_pics(obj.curr);
                    } else {
                        //初始加载相册列表
                        var load_albums = "{{ load_album }}".split(/\s*,\s*/);
                        var uri = "{{ (url_for('front.my', is_mgr=request.args.is_mgr) + '&album=')|safe if request.args.is_mgr else url_for('front.my', album='') }}";
                        var html = '<a href="' + uri + 'all#!picbed"><span class="layui-badge">所有图片</span></a>&nbsp;&nbsp;';
                        html += res.albums.map(function(album) {
                            var color = picbed.arrayContains(load_albums, album) ? "layui-bg-cyan" : "layui-bg-green";
                            return '<a href="' + uri + album + '#!picbed"><span class="layui-badge ' + color + '">' +  album + '</span></a>&nbsp;&nbsp;';
                        }).join('');
                        $("#albums").html(html);
                    }
                }
            });
            //渲染配置
            renderDefaultAlbumSelect();
        });
        //监听图片键盘
        document.onkeydown = function(e) {
            if (location.hash.startsWith("#!picbed")) {
                var keynum = window.event ? e.keyCode : e.which;
                switch(keynum){
                    case 37: //左键
                        $('div[id="page"]').find('a[class="layui-laypage-prev"]')[0].click(); //前一页点击事件
                        return false;
                    case 39: //右键
                        $('div[id="page"]').find('a[class="layui-laypage-next"]')[0].click(); //下一页点击事件
                        return false;
                }
            }
        }
        //渲染上传头像
        avatar.render({
            success: function(base64url, base64size) {
                picbed.ajax("{{ url_for('api.upload') }}", function(res) {
                    layer.msg("头像上传成功，请保存资料！", {icon:1});
                    $("input[name='avatar']").val(res.src);
                }, {
                    data: {picbed: base64url, album: 'avatar'}
                });
            }
        });
        //监听资料修改
        form.on('submit(profile)', function(data){
            var post = data.field;
            delete post.token;
            picbed.ajax("{{ url_for('api.my', Action='updateProfile') }}", function(res) {
                layer.msg("已修改资料", {icon:1});
                if (post.avatar) {
                    $("#avatar").attr("src", post.avatar);
                }
                if (post.nickname) {
                    $("#nickname").text(post.nickname);
                }
            }, {
                method: 'PUT',
                data: post
            });
            return false;
        });
        //监听密码修改
        form.on('submit(passwd)', function(data){
            picbed.ajax("{{ url_for('api.my', Action='updatePassword') }}", function(res) {
                layer.msg("已修改密码", {icon:1});
            }, {
                method: 'PUT',
                data: data.field
            });
            return false;
        });
        //监听token动作
        $("#createToken").on("click", function() {
            picbed.ajax("{{ url_for('api.token', Action='create') }}", function(res) {
                layer.msg("Token创建成功", {icon:1});
            　　$("#token").removeAttr("readonly");
                form.val("profileForm", {token: res.token});
                $("#token").attr("readonly","readonly");
                $("#yesToken").removeClass("layui-hide");
                $("#yesToken").addClass("layui-show");
                $("#noToken").removeClass("layui-show");
                $("#noToken").addClass("layui-hide");
            })
        });
        $("#revokeToken").on("click", function() {
            picbed.ajax("{{ url_for('api.token', Action='revoke') }}", function(res) {
                layer.msg("Token已销毁", {icon:1});
            　　$("#token").removeAttr("readonly");
                form.val("profileForm", {token: ''});
                $("#token").attr("readonly","readonly");
                $("#yesToken").removeClass("layui-show");
                $("#yesToken").addClass("layui-hide");
                $("#noToken").removeClass("layui-hide");
                $("#noToken").addClass("layui-show");
            })
        });
        $("#resetToken").on("click", function() {
            picbed.ajax("{{ url_for('api.token', Action='reset') }}", function(res) {
                layer.msg("Token重置成功", {icon:1});
            　　$("#token").removeAttr("readonly");
                form.val("profileForm", {token: res.token});
                $("#token").attr("readonly","readonly");
                $("#yesToken").removeClass("layui-hide");
                $("#yesToken").addClass("layui-show");
                $("#noToken").removeClass("layui-show");
                $("#noToken").addClass("layui-hide");
            })
        });
        $("#copyToken").on("click", function() {
            picbed.Clipboard.copy($("#token").val());
        });
        //监听相册修改
        form.on('submit(updateAlbumSubmit)', function(data){
            var album = data.field.album,
                sha = data.field.sha;
            picbed.ajax("{{ url_for('api.shamgr', sha='') }}" + sha, function(res) {
                layer.msg("已修改", {icon:1});
                shaDatas[sha]["album"] = album;

            }, {
                method: "PUT",
                data: {Action: "updateAlbum", album: album}
            });
            return false;
        });
        //监听开启用户脚本
        form.on('switch(userscript_btn)', function(data){
            if (data.elem.checked === true) {
                layer.tips('点击<i class="layui-icon layui-icon-link" style="font-size:12px"></i>安装或更新脚本', '#userscripturl', {tips:3});
            }
        });
        //监听用户设置
        form.on('submit(*)', function(data){
            if (document.forms['control'].checkValidity() === false) {
                layer.msg("发现部分参数不合法",{icon:0});
                document.forms['control'].reportValidity();
                return false;
            }
            if (!data.field.hasOwnProperty("ucfg_report_linktoken")) {
                data.field["ucfg_report_linktoken"] = 0;
            }
            if (!data.field.hasOwnProperty("ucfg_urlrule_inloadmypic")) {
                data.field["ucfg_urlrule_inloadmypic"] = 0;
            }
            if (!data.field.hasOwnProperty("ucfg_urlrule_incopyurl")) {
                data.field["ucfg_urlrule_incopyurl"] = 0;
            }
            if (!data.field.hasOwnProperty("ucfg_urlrule_incopyhtml")) {
                data.field["ucfg_urlrule_incopyhtml"] = 0;
            }
            if (!data.field.hasOwnProperty("ucfg_urlrule_incopyrst")) {
                data.field["ucfg_urlrule_incopyrst"] = 0;
            }
            if (!data.field.hasOwnProperty("ucfg_urlrule_incopymd")) {
                data.field["ucfg_urlrule_incopymd"] = 0;
            }
            picbed.ajax("{{ url_for('api.my', Action='updateUserCfg') }}", function(res) {
                if (res.code === 0) {
                    layer.msg("已修用户改配置", {icon:1});
                } else {
                    layer.msg(res.msg, {icon:0});
                }
            }, {
                method: "PUT",
                data: data.field
            });
            return false;
        });
        //以下是Token分权表格管理
        function renderOriginSelect(selectd_origin) {
            /*渲染origin的select下拉多选*/
            let cors = "{{ g.site.cors }}",
                origins = cors.split(/\s*,\s*/);
            let data = origins.map(function(o) {
                return {
                    hash: picbed.getHash(o),
                    origin: o
                };
            });
            if (selectd_origin) {
                let sos = selectd_origin.split(/\s*,\s*/);
                sos = sos.map(function(o) {
                    return picbed.getHash(o);
                });
                $("#render_multi_origin").attr("ts-selected", sos.join(","));
            }
            tableSelect.render({
                elem: '#render_multi_origin',	//定义输入框input对象 必填
                checkedKey: 'hash', //表格的唯一建值，非常重要，影响到选中状态 必填
                selectText: '确认选择',
                table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    data: data,
                    page: false,
                    size: 'sm',
                    width: 260,
                    cols: [[{
                        type: 'checkbox'
                    }, {
                        field: "hash",
                        title: "唯一标识",
                        hide: true
                    },{
                        field: "origin",
                        title: "来源地址",
                    }]]
                },
                done: function (elem, data) {
                    var NEWJSON = [];
                    layui.each(data.data, function (index, item) {
                        NEWJSON.push(item.origin);
                    });
                    $("#render_multi_origin").val(NEWJSON.join(","));
                }
            });
        }
        function renderEpSelect(selectd_ep) {
            /*渲染ep的select下拉多选*/
            let eps = ["api.upload", "api.waterfall", "api.login", "api.register", "front.userscript"];
            let data = eps.map(function(e) {
                return {
                    hash: picbed.getHash(e),
                    ep: e
                };
            });
            if (selectd_ep) {
                let ses = selectd_ep.split(/\s*,\s*/);
                ses = ses.map(function(e) {
                    return picbed.getHash(e);
                });
                $("#render_multi_ep").attr("ts-selected", ses.join(","));
            }
            tableSelect.render({
                elem: '#render_multi_ep',	//定义输入框input对象 必填
                checkedKey: 'hash', //表格的唯一建值，非常重要，影响到选中状态 必填
                selectText: '确认选择',
                table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    data: data,
                    page: false,
                    size: 'sm',
                    width: 200,
                    cols: [[{
                        type: 'checkbox'
                    }, {
                        field: "hash",
                        title: "唯一标识",
                        hide: true
                    },{
                        field: "ep",
                        title: "端点(接口)",
                    }]]
                },
                done: function (elem, data) {
                    var NEWJSON = [];
                    layui.each(data.data, function (index, item) {
                        NEWJSON.push(item.ep);
                    });
                    $("#render_multi_ep").val(NEWJSON.join(","));
                }
            });
        }
        function renderMethodSelect(selectd_method) {
            /*渲染method的select下拉多选*/
            let methods = ["get", "post", "put", "delete", "head"];
            let data = methods.map(function(m) {
                return {
                    hash: picbed.getHash(m),
                    method: m
                };
            });
            if (selectd_method) {
                let sms = selectd_method.split(/\s*,\s*/);
                sms = sms.map(function(m) {
                    return picbed.getHash(m);
                });
                $("#render_multi_method").attr("ts-selected", sms.join(","));
            }
            tableSelect.render({
                elem: '#render_multi_method',	//定义输入框input对象 必填
                checkedKey: 'hash', //表格的唯一建值，非常重要，影响到选中状态 必填
                selectText: '确认选择',
                table: {	//定义表格参数，与LAYUI的TABLE模块一致，只是无需再定义表格elem
                    data: data,
                    page: false,
                    size: 'sm',
                    width: 150,
                    cols: [[{
                        type: 'checkbox'
                    }, {
                        field: "hash",
                        title: "唯一标识",
                        hide: true
                    },{
                        field: "method",
                        title: "方法",
                    }]]
                },
                done: function (elem, data) {
                    var NEWJSON = [];
                    layui.each(data.data, function (index, item) {
                        NEWJSON.push(item.method);
                    });
                    $("#render_multi_method").val(NEWJSON.join(","));
                }
            });
        }
        function showCopyLinkToken(LinkToken) {
            /*显示LinkToken复制弹框*/
            let content = [
                '<div style="padding: 15px"><p>已成功添加新引用！</p>',
                '<scan style="color:green;font-weight:bold">LinkToken:</scan> ' + picbed.str2star(LinkToken, 8, -8),
                '<scan style="color:green;font-weight:bold">LinkScript:</scan> 在外部网站中使用js自动上传到picbed。',
                '&nbsp;&nbsp;&nbsp;- 手动方式需要写js，在引用页面调用up2picbed函数初始化，相对复杂，但灵活度高!',
                '&nbsp;&nbsp;&nbsp;- 自动方式不需要写js，所有选项可通过dataset定义，但有局限，详细使用请参考文档！',
                '您可以使用以下按钮完成快捷复制，并<a href="https://docs.saintic.com/picbed/usage.html#linktoken" target="_blank" title="LinkToken文档" style="color:#009688">查阅文档</a>！',
                '</div>',
            ].join("<br>");
            let sdk = "{{ url_for('static', filename='sdk/uploader.js', _external=True) }}",
                url = "{{ url_for('api.upload', _external=True) }}";
            layer.open({
                type: 1,
                title: false,
                closeBtn: true,
                area: '430px',
                maxHeight: '500px',
                skin: 'linktoken-layer',
                shade: 0.1,
                shadeClose: true,
                btn: ['手动引用', '自动引用', 'LinkToken', 'JS'],
                btnAlign: 'c',
                content: content,
                yes: function(index, layero){
                    //按钮【复制手动引用】的回调
                    picbed.Clipboard.copy(`<script src="${sdk}" data-url="${url}" data-token="${LinkToken}"><\/script>`);
                    return false;
                },
                btn2: function(index, layero){
                    //按钮【复制自动引用】的回调
                    picbed.Clipboard.copy(`<script src="${sdk}" data-url="${url}" data-token="${LinkToken}" data-auto="true"><\/script>`);
                    return false;
                },
                btn3: function(index, layero) {
                    //按钮【仅复制LinkToken】的回调
                    picbed.Clipboard.copy(LinkToken);
                    return false;
                },
                btn4: function(index, layero) {
                    //按钮【仅复制JS】的回调
                    picbed.Clipboard.copy(sdk);
                    return false;
                },
            });
        }
        var tableIns = table.render({
            elem: '#linktokenTable',
            url: '{{ url_for("api.link") }}',
            page: false,
            size: 'sm',
            cols: [
                [{
                        field: 'LinkId',
                        title: 'ID',
                        width: 60,
                        fixed: 'left'
                    },
                    {
                        field: 'LinkToken',
                        title: 'LinkToken',
                        hide: true
                    },
                    {
                        field: 'user',
                        title: '所属',
                        hide: true,
                    },
                    {
                        field: 'album',
                        title: '相册',
                        width: 90,
                    },
                    {
                        field: 'comment',
                        title: '备注',
                    },
                    {
                        field: 'allow_origin',
                        title: '允许源域名',
                    },
                    {
                        field: 'allow_ip',
                        title: '允许源IP',
                        width: 80
                    },
                    {
                        field: 'allow_ep',
                        title: '允许路由端点',
                    },
                    {
                        field: 'allow_method',
                        title: '允许方法',
                        width: 80
                    },
                    {
                        field: 'exterior_relation',
                        title: '平行规则',
                        hide: true
                    },
                    {
                        field: 'interior_relation',
                        title: '内部规则',
                        hide: true
                    },
                    {
                        field: 'ctime',
                        title: '创建时间',
                        width: 145,
                        hide: true,
                        templet: function (d) {
                            return util.toDateString(parseInt(d.ctime) * 1000);
                        }
                    },
                    {
                        field: 'mtime',
                        title: '修改时间',
                        width: 145,
                        hide: true,
                        templet: function (d) {
                            return d.mtime ? util.toDateString(parseInt(d.mtime) * 1000) : '暂无修改';
                        }
                    },
                    {
                        field: 'status',
                        title: '状态',
                        width: 70,
                        templet: function (d) {
                            return (d.status === 1 || d.status === "1") ?  '<scan style="color:#5FB878">启用中</scan>' : '<scan style="color:#FF5722">已禁用</scan>';
                        }
                    },
                    {
                        fixed: 'right',
                        width: 170,
                        align: 'left',
                        toolbar: '#linktoken_action'
                    }
                ]
            ],
            toolbar: '#toolbar',
            title: 'LinkToken',
            defaultToolbar: [{
                title: '重载表格',
                layEvent: 'LAYTABLE_RELOAD', //事件名，用于 toolbar 事件中使用
                icon: 'layui-icon-refresh' //图标类名
            }, 'filter', 'print', 'exports'],
            done: function() {
                $("#linktokentip").hover(function () {
                    let tip = [
                        "&nbsp;&nbsp;&nbsp;&nbsp;Token分权引用(LinkToken)是将Token的映射，Token最小权限与安全限定下的调用方式。",
                        "用户可以创建分权引用，定义调用此引用的安全来源主机地址、IP，并限定访问某个路由或某个路径，提交后会得到一个最小权限的LinkToken！",
                        "然后就可以在其他网站跨域调用，比如上传图片，即便丢失也不会影响其他，禁用或删除即可，不会泄露Token。",
                        "更多请参考文档：<a href='https://docs.saintic.com/picbed/usage.html#linktoken' target='_blank' style='color:#009688'>LinkToken</a>",
                    ].join("<br>&nbsp;&nbsp;&nbsp;&nbsp;");
                    layer.tips(tip, this, {tips: 3, time: 0});
                }, closeTip);
            }
        });
        //监听工具条
        table.on('tool(linktokenTable)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === "edit") {
                laytpl(show_editor_area.innerHTML).render({action: "edit", cors: "{{ g.site.cors }}"}, function (html) {
                    layer.open({
                        type: 1,
                        shade: 0.1,
                        shadeClose: true,
                        cloaseBtn: true,
                        title: '修改LinkToken',
                        skin: 'layui-layer-molv',
                        area: '400px',
                        content: html,
                        success: function () {
                            form.val("linktokenForm", data);
                            form.render();
                            renderOriginSelect(data.allow_origin);
                            renderEpSelect(data.allow_ep);
                            renderMethodSelect(data.allow_method);
                        }
                    });
                });
            } else if (layEvent === "del") {
                layer.confirm('确认删除引用吗？', {
                    icon: 3,
                    title: false,
                    closeBtn: 0,
                    btn: ['确认删除','取消'] //按钮
                }, function(index) {
                    picbed.ajax("{{ url_for('api.link') }}", function(res) {
                        layer.msg("已删除引用", {icon:1});
                        obj.del();
                    }, {
                        method: "DELETE",
                        data: {LinkId:data.LinkId}
                    });
                    layer.close(index);
                }, function(index){
                    layer.close(index);
                });
            } else if (layEvent === "copy") {
                showCopyLinkToken(data.LinkToken);
            }  else if (layEvent === "disable") {
                picbed.ajax('{{ url_for("api.link", Action="disable") }}', function(res) {
                    layer.msg("已禁用", {icon:1});
                    obj.update({status: 0});
                }, {
                    method: "PUT",
                    data: {LinkId: data.LinkId}
                });
            }   else if (layEvent === "enable") {
                picbed.ajax('{{ url_for("api.link", Action="enable") }}', function(res) {
                    layer.msg("已启用", {icon:1});
                    obj.update({status: 1});
                }, {
                    method: "PUT",
                    data: {LinkId: data.LinkId}
                });
            }
        });
        //监听头部工具栏事件
        table.on('toolbar(linktokenTable)', function (obj) {
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === "newLink") {
                laytpl(show_editor_area.innerHTML).render({action: "create", cors: "{{ g.site.cors }}"}, function (html) {
                    layer.open({
                        type: 1,
                        shade: 0.1,
                        shadeClose: true,
                        cloaseBtn: true,
                        title: '添加LinkToken',
                        skin: 'layui-layer-molv',
                        area: '400px',
                        content: html,
                        success: function () {
                            form.render();
                            renderOriginSelect();
                            renderEpSelect();
                            renderMethodSelect();
                        }
                    });
                });
            } else if (layEvent === "LAYTABLE_RELOAD") {
                tableIns.reload();
            }
        });
        //监听引用添加按钮提交
        form.on('submit(linktokenAdd)', function (data) {
            picbed.ajax('{{ url_for("api.link") }}', function(res) {
                layer.closeAll('page');
                showCopyLinkToken(res.LinkToken);
                tableIns.reload();
            }, {
                data: data.field
            });
            return false;
        });
        //监听引用修改按钮提交
        form.on('submit(linktokenModify)', function (data) {
            picbed.ajax('{{ url_for("api.link") }}', function(res) {
                layer.msg("已修改", {icon:1});
                layer.closeAll('page');
                tableIns.reload();
            }, {
                method: "PUT",
                data: data.field
            });
            return false;
        });
    });
</script>
{% endblock %}
